//
//  WowDaraNewsContent.m
//  WowDara
//
//  Created by Siroj Chongkolwanont on 5/1/56 BE.
//  Copyright (c) 2556 Siroj Chongkolwanont. All rights reserved.
//

#import "WowDaraNewsContent.h"

@interface WowDaraNewsContent ()

@end



@implementation WowDaraNewsContent

@synthesize descText;
@synthesize feed;
@synthesize dateTimeLabel;
@synthesize headlineLabel;
@synthesize contentImage;
@synthesize news_id;

id jsonObjectFromUrlString(NSString *urlString);

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{

    
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage  imageNamed:@"toolbar_logo.png"]];

    UIButton *button1 = [[UIButton alloc] init];
    button1.frame= CGRectMake(0,0,43,32);
    [button1 setBackgroundImage:[UIImage imageNamed: @"nav_back.png"] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1];
    
    
    
    UIButton *button2 = [[UIButton alloc] init];
    button2.frame= CGRectMake(0,0,43,32);
    [button2 setBackgroundImage:[UIImage imageNamed: @"nav_sharet.png"] forState:UIControlStateNormal];
    //[button2 addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button2];
    
    
    [super viewDidLoad];
    


	// Do any additional setup after loading the view.
    //[descLabel sizeToFit];
    [headlineLabel sizeToFit];
    headlineLabel.text = feed.name;
    
    NSString *content_str = [NSString stringWithFormat:@"http://119.59.127.95/~wowdara/android/getNewsFeedDetail.php?id=%@", news_id];

    
    NSDictionary *publicBanner =  jsonObjectFromUrlString(content_str);
    dateTimeLabel.text = [publicBanner valueForKey:@"update_date"];
    [descText loadHTMLString:[publicBanner valueForKey:@"description"] baseURL:nil];
    
    NSString *url_picture = @"http://119.59.127.95/~wowdara/";
    
    url_picture = [url_picture stringByAppendingString:[publicBanner valueForKey:@"image_inside"]];
    
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url_picture]];
    
    contentImage.image = [UIImage imageWithData:imageData];
    

    
    //UIImage *buttonBack24 = [[UIImage imageNamed:@"nav_contact.png"]
    //                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
    //[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24
          //                                            forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    //[[UIBarButtonItem appearance] setBackBarButtonItem:[[UIBarButtonItem alloc]initWithCustomView:button1]];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backAction:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end
